package org.studle.domain;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Event {
	final static int EXPIRATION_YEAR = 2020;
	final static int EXPITATION_MONTH = 12;
	final static int EXPIRATION_DATE = 31;
	
	final static String KEY_PREFFIX = "event";
	private static int keyNumber = 0;
	
	private String name;
	private String description;
	private ArrayList<Person> owners;
	private Date expirationDate;
	private String id;
	
	private static Calendar expCalendar = new GregorianCalendar(EXPIRATION_YEAR, EXPITATION_MONTH, EXPIRATION_DATE);
	
	public Event(String name, String description) {
		this.name = name;
		this.description = description;
		this.owners = new ArrayList<Person>();
		this.expirationDate = expCalendar.getTime();
		this.id = KEY_PREFFIX + keyNumber++;
	}
	
	public boolean isActive(){
		return expirationDate.after(new Date());
	}
	
	public void addOwner(Person owner){
		owners.add(owner);
	}
	
	public String getName(){
		return name;
	}

	public void setDescription(String description){
		this.description = description;
	}
	
	public String getDescription(){
		return description;
	}
	
	public void setExpired() throws IllegalStateException{
		if (!this.isActive()) throw new IllegalStateException("Event is expired");
		this.expirationDate = new Date();
	}
	
	public String getID(){
		return id;
	}
	
}
